
#ifndef _MEMBER_BPIXMAP_H_
#define _MEMBER_BPIXMAP_H_

#include <BImage>
#include <BOpenGL>
#include <BImage>
#include <BRender>
#include <BWidget>
#include <BMouseEvent>
#include <BDragEvent>
#include <BFocusEvent>
#include <BDisplay>
#include <BDrag>
#include "IGLState.h"

#define display_member(display)		((member_BDisplay*)((BDisplay*)display)->_ptr)

namespace BWE
{
	class member_BDisplay : public IGLState
	{
	public:
		member_BDisplay(BDisplay* display);
		~member_BDisplay();

		bool check() const;

		void fresh();
		void frame();

		void updateWidget(BWidget* widget, const BEvent& event);
		void freshWidget(BWidget* widget, const BEvent& event);

		bool hover(BWidget* widget);
		bool focus(BWidget* widget);

		BWidget* widgetUnderPoint(const BPoint& point);
		BWidget* findWidget(BWidget* widget, const BPoint& point, const BRect& clip);
		BWidget* findPopupWidget(BWidget* widget, const BPoint& point, const BRect& clip);

		void refreshWindow();
		void refreshWidget(BWidget* widget);
		void paintWidget(BWidget* widget, const BRect& clip, const BPoint& offset, int frameHeight);
		void paintPopupWidget(BWidget* widget, const BRect& clip, const BPoint& offset, int frameHeight);
		void paintCursor();
		void paintDrag();
		void paintTip();

		void slotMousePress(BMouseEvent& mouseEvent);
		void slotMouseRelease(BMouseEvent& mouseEvent);
		void slotMouseMove(BMouseEvent& mouseEvent);
		void slotMouseWheel(BMouseEvent& mouseEvent);
		void slotDragMove(BDragEvent& dragEvent);
		void slotDragDrop(BDragEvent& dragEvent);

	public:
		BDisplay*			boss;
		BSize				size;
		BImageHolder		wallpaper;
		BColor				bgColor;
		BWidgetHolder		widget;

		bool				dirty;
		GLuint				fbo;
		GLuint				rbo_depth;
		GLuint				rbo_stencil;

	public:
		BDrag*				drag;
		BWidget*			host;
		BWidget*			hoverWidget;
		BWidget*			focusWidget;
		BWidgetArray		popupWidgets;

		BPoint				cursorPos;
		bool				refresh;
		bool				focusing;
		bool				showTooltip;
		BRect				tipsRect;

		BRect				currentRect;
		bool				mouse_pressed;
		double				mouse_pressed_time;
		BPoint				mouse_pressed_pos;
		double				mouse_click_time;
		BPoint				mouse_click_pos;
		BPoint				mouse_pos;
	};
}


#endif